Added turns_only and turns_important to saroute
authorparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 6 Jul 2004 14:04:03 +0000 (14:04 +0000)
committerparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 6 Jul 2004 14:04:03 +0000 (14:04 +0000)
gpsbabel/README
gpsbabel/defs.h
gpsbabel/saroute.c
gpsbabel/smplrout.c

index 4c3738e794dc2546c31ec4c037db156525bc6379..a47ff7050976d602068819d7020ffdfe23e21a0a 100644 (file)
@@ -470,7 +470,20 @@ THE FORMATS
 
        This is a catch-all used by many Delorme mapping products and
        reads the anr, rte, and rtd formats as either tracks or routes.
+
+        The 'turns_only' option causes GPSBabel to read only the waypoints 
+        associated with named turns.  This should create a list of waypoints 
+        that correspond to the itinerary from Street Atlas.
        
+        The 'turns_important' option only makes sense in conjunction with 
+        the 'simplify' filter.  It ensures that the route simplification 
+        process will remove the points corresponding to turns only after
+        it has removed all other route points.
+
+        Both options only apply to route files from newer versions of 
+        DeLorme software; older versions didn't store the turn information
+        with the route.
+
     saplus
 
         This format is for Street Atlas USA 2004 Plus.  
index b6d36c20fdbaef793ff873912dd75ef0994e8e4b..a6fbfe7f6553111a6341e49362ba4e66625cae75 100644 (file)
@@ -193,6 +193,17 @@ typedef struct {
        const char *icon_descr;
        time_t creation_time;   /* standardized in UTC/GMT */
        int centiseconds;       /* Optional hundredths of a second. */
+       
+       /*
+        * route priority is for use by the simplify filter.  If we have
+        * some reason to believe that the route point is more important,
+        * we can give it a higher (numerically; 0 is the lowest) priority.
+        * This causes it to be removed last.
+        * This is currently used by the saroute input filter to give named
+        * waypoints (representing turns) a higher priority.
+        */
+       int route_priority;
+       
        geocache_data gc_data;
        xml_tag *gpx_extras;
        void *extra_data;       /* Extra data added by, say, a filter. */
index f79a50795b2db696f13f2a46c84070bd2c1302ce..04d66aeb7834d5f275f329d0aad5c06de0b70b07 100644 (file)
 
 FILE *infile;
 
+char *turns_important = NULL;
+char *turns_only = NULL;
+
+static
+arglist_t saroute_args[] = {
+       {"turns_important", &turns_important, 
+               "Keep turns if simplify filter is used", ARGTYPE_BOOL },
+       {"turns_only", &turns_only, "Only read turns; skip all other points",
+               ARGTYPE_BOOL },
+       {0, 0, 0, 0 }
+};
+
 unsigned short
 ReadShort(FILE * f)
 {
@@ -221,12 +233,20 @@ my_read(void)
                                wpt_tmp->latitude = lat;
                                wpt_tmp->longitude = -lon;
                                wpt_tmp->shortname = (char *) xmalloc(7);
+                               if ( turns_important && stringlen ) 
+                                       wpt_tmp->route_priority=1;
                                sprintf( wpt_tmp->shortname, "\\%5.5x", 
                                                serial++ );
-                               route_add_wpt(track_head, wpt_tmp);
+                               if ( !turns_only || stringlen ) 
+                                       route_add_wpt(track_head, wpt_tmp);
        
                                latlon++;
                                coordcount--;
+                               stringlen = 0;
+                               /* the stop point is a "turn" */
+                               if ( coordcount == 1 && count == 0 ) {
+                                       stringlen = 1;
+                               }
                        }
                        xfree(record);
                }
@@ -252,5 +272,5 @@ ff_vecs_t saroute_vecs = {
        NULL,
        my_read,
        NULL,
-       NULL
+       saroute_args
 };
index 5360d103d4577212770eb911439932cb352ad3da..f205921493ed42343c12f0d02bedfb3622e2d09c 100644 (file)
@@ -29,7 +29,7 @@ static char *countopt = NULL;
 
 static
 arglist_t routesimple_args[] = {
-       {"count", &countopt,  "Maximum number of points in final route", 
+       {"count", &countopt,  "Maximum number of points in route", 
                ARGTYPE_INT | ARGTYPE_REQUIRED},
        {0, 0, 0, 0}
 };
@@ -108,9 +108,14 @@ compute_xte( struct xte *xte_rec ) {
 int
 compare_xte( const void *a, const void *b )
 {
-       double foo = (((struct xte *)a)->distance - ((struct xte *)b)->distance );
-       if ( foo < 0 ) return 1;
-       if ( foo > 0 ) return -1;
+       double distdiff = ((struct xte *)a)->distance - 
+                         ((struct xte *)b)->distance;
+       int priodiff = ((struct xte *)a)->intermed->wpt->route_priority -
+                      ((struct xte *)b)->intermed->wpt->route_priority;
+       if ( priodiff < 0 ) return 1;
+       if ( priodiff > 0 ) return -1;
+       if ( distdiff < 0 ) return 1;
+       if ( distdiff > 0 ) return -1;
        return 0;
 }
 
@@ -134,8 +139,7 @@ void
 shuffle_xte( struct xte *xte_rec )
 {
        struct xte tmp_xte;
-       while ( xte_rec > xte_recs && 
-                       xte_rec->distance > xte_rec[-1].distance ) {
+       while ( xte_rec > xte_recs && compare_xte(xte_rec, xte_rec-1) < 0 ) {
                tmp_xte.distance = xte_rec->distance;
                tmp_xte.ordinal = xte_rec->ordinal;
                tmp_xte.intermed = xte_rec->intermed;
@@ -150,7 +154,7 @@ shuffle_xte( struct xte *xte_rec )
                xte_rec->intermed->xte_rec = xte_rec;
        }
        while ( xte_rec - xte_recs < xte_count-2 && 
-                       xte_rec->distance < xte_rec[1].distance ) {
+                       compare_xte( xte_rec, xte_rec+1) > 0 ) {
                tmp_xte.distance = xte_rec->distance;
                tmp_xte.ordinal = xte_rec->ordinal;
                tmp_xte.intermed = xte_rec->intermed;